package com.qgs.waf.gen;

import java.util.List;
import java.util.Random;

import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisConnectionUtils;
import org.springframework.data.redis.core.RedisTemplate;

import com.google.gson.JsonObject;
import com.qgs.waf.data.Datas;
import com.qgs.waf.redis.GenRandomData;
import com.qgs.waf.util.ApplicationContextSupport;
import com.qgs.waf.util.JSonUtil;

public class AtatisticsAttacksList extends ApplicationContextSupport {
	public void gen() {
		RedisTemplate rt = (RedisTemplate) ac.getBean("jedisTemplate");
		RedisConnectionFactory factory = rt.getConnectionFactory();
		RedisConnection redisConnection = RedisConnectionUtils.getConnection(factory);
		redisConnection.openPipeline();
		// 生成随机数
		genRandomHashDate(redisConnection);
		List results = redisConnection.closePipeline();
		System.out.println(results);
		redisConnection.close();
		System.out.println("end ......");
	}

	public static void main(String[] args) {
		AtatisticsAttacksList sas = new AtatisticsAttacksList();
		sas.gen();
	}

	/**
	 * 制造攻击列表数据
	 * 
	 * @param redisConnection
	 */
	public static void genRandomHashDate(RedisConnection redisConnection) {
		int ran;
		for (int i = 1; i < 1000; i++) {
			ran=new Random().nextInt(80);
			ran=((ran==0)?1:ran);
			redisConnection.zAdd("statistics.attacks.list".getBytes(),ran ,JSonUtil.object2JSon(GenRandomData.getCS()).getBytes());
		}
	}
}